﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Hospital_UpBuyPlan : System.Web.UI.Page
{
    string projectid, strSql, BuyPlanId, strConditions, Accountid_yy, buystate;
    protected void Page_Load(object sender, EventArgs e)
    {
        BuyPlanId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["BuyPlanId"]));
        projectid = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);

        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            Accountid_yy = SysFun.ToTrim(_Account.AccountId);
            LabHospital.Text = _Account.DWName;
            if (!IsPostBack)
            {

                Db db = new Db();
                System.Data.IDataReader dr;
                strSql = "select * from PurchasePlan where BuyPlanId=" + BuyPlanId + " and AccountId_YY=" + _Account.AccountId;
                dr = db.DataReader(strSql);
                if (dr.Read())
                {
                    txtStartTime.Text = Convert.ToDateTime(dr["StartTime"]).ToShortDateString();
                    txtEndTime.Text = Convert.ToDateTime(dr["EndTime"]).ToShortDateString();
                    txtPlanName.Text = SysFun.ToTrim(dr["PlanName"]);
                    rdoBuyStatus.SelectedValue = SysFun.ToTrim(dr["BuyStatus"]);
                    txtRemarks.Text = SysFun.ToTrim(dr["Remarks"]);
                    buystate = SysFun.ToTrim(dr["BuyStatus"]);
                    TextLname.Text = SysFun.ToTrim(dr["RelationMen"]);
                    TextPhote.Text = SysFun.ToTrim(dr["RelationPhone"]);
                    TextJName.Text = SysFun.ToTrim(dr["ConstructMen"]);
                    if (SysFun.ToInt(dr["BuyStatus"]) == 2)
                    {
                        BtnSave.Enabled = false;                        
                    }
                    
                }
                else
                {
                    Response.Write("对不起，你没有权限浏览不属于自身采购单的药品");
                    Response.End();
                }
                dr.Close();
                dr.Dispose();
                db.Close();




            }
          
        }     
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {

        if (DateTime.Parse(SysFun.ToTrim(txtStartTime.Text)) > DateTime.Parse(SysFun.ToTrim(txtEndTime.Text)))
        {
            Response.Write("<script>window.alert('开始时间不得晚于结束时间');</script>");
            return;
        }
        if (SysFun.ToTrim(TextLname.Text) == "")
        {
            Response.Write("<script>window.alert('联系人必填！');</script>");
            return;
        }
        if (SysFun.ToTrim(TextPhote.Text) == "")
        {
            Response.Write("<script>window.alert('联系电话！');</script>");
            return;
        }
        if (SysFun.ToTrim(TextJName.Text) == "")
        {
            Response.Write("<script>window.alert('建单人！');</script>");
            return;
        }
        string str;
        str = "update PurchasePlan set PlanName='" + SysFun.ToTrim(txtPlanName.Text) + "',StartTime='" + SysFun.ToTrim(txtStartTime.Text) + "',EndTime='" + SysFun.ToTrim(txtEndTime.Text) + "',Remarks='" + SysFun.ToTrim(txtRemarks.Text) + "',RelationMen='" + SysFun.ToTrim(TextLname.Text) + "',RelationPhone='" + SysFun.ToTrim(TextPhote.Text) + "',ConstructMen='"+SysFun.ToTrim(TextJName.Text)+"' where BuyPlanId=" + BuyPlanId;
        Db db = new Db();
        db.Command(str);
        db.Close();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "PurchasePlan", str, "..Hospital/UpBuyPlan.aspx");
        Response.Write("<script>window.alert('修改成功');window.opener.location.reload();window.close();</script>");

    }
}
